﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports Exp.DAL
Imports Exp.Model

Namespace Exp.DATA_Service

    Public Class Brand_Service
        Private _objBrand As New REM_Brand


        Public Sub New(objBrand As REM_Brand)
            _objBrand = objBrand
        End Sub

        Public Sub New()

        End Sub

        Public Function GetAll() As List(Of REM_Brand)
            Dim ctx As New EXPEntities
            Dim list = ctx.REM_Brand.ToList()
            Return list

        End Function
        Public Function GetByName(ByVal sName As String) As List(Of REM_Brand)
            Dim ctx As New EXPEntities
            Dim lstObj As New List(Of REM_Brand)
            lstObj = ctx.REM_Brand.Where(Function(o) o.BrandName = sName).ToList()
            Return lstObj
        End Function

        Public Function GetByID(ByVal ID As Integer) As REM_Brand
            Dim ctx As New EXPEntities
            Dim obj = ctx.REM_Brand.Where(Function(o) o.Brand_ID = ID).FirstOrDefault()
            Return obj
        End Function
        Public Function GetLastID() As Integer
            Dim ctx As New EXPEntities
            Dim iReturn As Integer = 0
            Dim lstObj As New List(Of REM_Brand)
            lstObj = ctx.REM_Brand.ToList()
            lstObj = ctx.REM_Brand.OrderByDescending(Function(p) p.Brand_ID).ToList()
            If Not lstObj Is Nothing Then
                iReturn = lstObj.Item(0).Brand_ID + 1
            End If
            Return iReturn
        End Function

        Public Sub Add(ByVal objBrand As REM_Brand)
            Dim ctx As New EXPEntities
            ctx.REM_Brand.AddObject(objBrand)
            ctx.SaveChanges()
        End Sub

        Public Sub Edit(ByVal objBrand As REM_Brand)
            Dim ctx As New EXPEntities
            Dim obj = ctx.REM_Brand.Where(Function(o) o.Brand_ID = objBrand.Brand_ID).FirstOrDefault()
            obj.BrandName = objBrand.BrandName
            obj.isActive = objBrand.isActive
            obj.UpdateDate = objBrand.UpdateDate
            obj.UpdateUser = objBrand.UpdateUser
            ctx.SaveChanges()
        End Sub

        Public Sub Delete(ByVal iBrandID As Integer)
            Dim ctx As New EXPEntities
            Dim obj = ctx.REM_Brand.Where(Function(o) o.Brand_ID = iBrandID).FirstOrDefault()
            ctx.REM_Brand.DeleteObject(obj)
            ctx.SaveChanges()
        End Sub
    End Class
End Namespace

